package com.aaa.controller;

import com.aaa.service.CartService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("cart")
public class CartController {

    @Resource
    CartService cartService;

    @RequestMapping("selectCart")
    @ResponseBody
    public List<Map<String,Object>> selectCart(String userid){
        return cartService.selectCart(userid);
    }

    @RequestMapping("addCart")
    @ResponseBody
    public boolean addCart(String name,String price,Integer id,String user_id,String num){
        Date date=new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        sdf.format(date);
        System.out.println(sdf.format(date));
        String create_date=sdf.format(date);
        return cartService.addCart(id,price,name,create_date,user_id,num)==1?true:false;
    }

    @RequestMapping("removeProductById")
    @ResponseBody
    public boolean removeProductById(String userid,String id){
        return cartService.removeProductById(userid,id)==1?true:false;
    }
}
